var SharedCoupon = getPageCode("share_coupon"); //分享券编码
if(SharedCoupon) {
    SharedCoupon = JSON.parse(decodeURI(decodeURI(SharedCoupon)))
    var SHARE_ID = SharedCoupon.SHARE_ID;
    var productName = SharedCoupon.productName;
}

$(document).ready(function () {
    // initStoreId(function () {
        var orderShareGetPath = "order/share/get";
        var orderShareGetParams = {
            "SHARE_ID":SHARE_ID,
            "STORE_ID":STORE_ID
        };
        /*if(sessionStorage.getItem(SHARE_ID)) {
            return showErroMsg("分享券已领取，返回首页!",function () {
                location.replace("./index.html");
            },false);
        }*/
        request(orderShareGetPath,orderShareGetParams,function (res) {
            var flg = /^0+$/ig.test(res.RSPCD); //全零true
            if(res.RSPCD == "OFF10337") {
                return showErroMsg("别太贪心了，大家分享喽!",function () {
                    location.replace("./index.html");
                },false);
            }
            if(res.RSPCD == "OFF10336") {
                return showErroMsg("分享券已被抢完了，返回首页！",function () {
                    location.replace("./index.html");
                },false);
            }
            if(!flg) {
                $("#to_use").attr("disabled",true);
                $(".success-text").text("分享券已被抢完了！");
                $(".pay-success-icon").attr("src","../assets/img/ico_remind.png");
                return showErroMsg("分享券已被抢走了，返回首页!",function () {
                    location.replace("./index.html");
                },false);
                $(".remind-info1").text('在“我的 》分享券”找找其他的分享券');
            } else {
                $(".success-text").text("领取成功！");
                // sessionStorage.setItem(SHARE_ID,1);
            }
        })
    // })

});
$("#to_use").on("tap",function () {
    location.replace("./my_share_coupon.html");
})